﻿using Loong.Admin.ExceptionHandling;
using Loong.Admin.Reflection;

namespace Microsoft.AspNetCore.Builder
{
    public static class AdminApplicationBuilderExtensions
    {
        public static IApplicationBuilder UseAdminExceptionHandling(this IApplicationBuilder app)
        {
            var exceptionHandlingMiddlewareMarker = ReflectionHelper.GetFieldValue(
                typeof(AbpApplicationBuilderExtensions),
                "ExceptionHandlingMiddlewareMarker")
                ?.ToString();
            if (!exceptionHandlingMiddlewareMarker.IsNullOrEmpty())
            {
                app.Properties[exceptionHandlingMiddlewareMarker] = true;
            }

            return app.UseMiddleware<AdminExceptionHandlingMiddleware>();
        }
    }
}
